import { GModuleEvent } from "../../../mvc/GModuleEvent";
import { Cache } from "../../../cache/Cache";
import { RolePlayer } from "../../../scene/player/entity/RolePlayer";
import { PlayerEvent } from "../../../scene/events/PlayerEvent";
import { NetDispatcher } from "../../../../mvc/core/NetDispatcher";
import { ServerCommand } from "../../../mvc/ServerCommand";
import { ObjCreate } from "../../common/ObjCreate";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { SkillConfig } from "../../../resource/SkillConfig";
import { Language } from "../../../../../extend/language/Language";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { EffectManager } from "../../../manager/EffectManager";
import { LookupPlayerData } from "../LookupPlayerData";
import { ToolTipInfo } from "../../../model/ToolTipInfo";
import { SecondCareerConfig } from "../../../resource/SecondCareerConfig";
import { ECareerSecondTran } from "../../../../../Message/Public/ECareerSecondTran";
import { EquipmentUtil } from "../../common/util/EquipmentUtil";
import { NormalTooltip } from "../../common/tooltip/NormalTooltip";
import { SSuitSkillInfo } from "../../../../../Message/Game/SSuitSkillInfo";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class PlayerSuitPanel
    
    export  class PlayerSuitPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._glowYellow = new Object /* flash.filters.GlowFilter */(16776960, 1, 3, 3, 5);
            return;
        }

        public set mode(arg1: string)
        {
            this._mode = arg1;
            this.init();
            return;
        }

        public set curCareer(arg1: int)
        {
            this._curCareer = arg1;
            return;
        }

        /* internal  */init(): void
        {
            if (this._mode == GModuleEvent.Mode_Self) 
            {
                this._level = Cache.instance.role.entityInfo.level;
                this.suitLock();
                this.suitSkill();
                RolePlayer.instance.addEventListener(PlayerEvent.RoleLevelUpdate, this.onRoleLevelUpdateHandler);
                NetDispatcher.addCmdListener(ServerCommand.SuitSkillInfoCommand, this.onSuitSkillInfoCommandHandler);
            }
            return;
        }

        /* internal  */onRoleLevelUpdateHandler(arg1: Object): void
        {
            if (this._mode == GModuleEvent.Mode_Self) 
            {
                this._level = Cache.instance.role.entityInfo.level;
                this.suitLock();
                this.suitSkill();
            }
            return;
        }

        /* internal  */suitLock(): void
        {
            if (this._level >= 30 && this._suitLockBtn == null) 
            {
                this._suitLockBtn = ObjCreate.createGButton("", 0, 0, 23, 23, this, "SuitGrayBtn");
                this._suitLockBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onSuitLockBtnClickHandler);
            }
            return;
        }

        /* internal  */suitSkill(): void
        {
            if (this._level >= 60 && this._suitSkillBtn == null) 
            {
                this._suitSkillBtn = ObjCreate.createGButton("", 0, 28, 23, 23, this, "SuitGrayBtn");
                this._suitSkillBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onSuitSkillBtnClickHandler);
                this.onSuitSkillInfoCommandHandler(Cache.instance.role.suitSkillInfo);
            }
            return;
        }

        /* internal  */onSuitLockBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.PlayerSuitLockOpen));
            return;
        }

        /* internal  */onSuitSkillBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            var loc2=null;
            if (this._skillInfo && this._skillInfo.level == 0 && this._skillInfo.skillId > 0) 
            {
                loc1 = SkillConfig.instance.getInfoByName(this._skillInfo.skillId);
                loc2 = Language.getStringByParam(35998, loc1.skillName);
                Alert.okLabel = Language.getString(40606);
                Alert.show(loc2, null, Alert.OK, null, this.onAlertCloseHandler);
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PlayerSuitSkillOpen));
            }
            EffectManager.glowFilterUnReg(this._suitSkillBtn);
            return;
        }

        /* internal  */onAlertCloseHandler(arg1: int): void
        {
            if (Alert.OK == arg1) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.SuitSkillUpgrade, 0));
                Dispatcher.dispatchEvent(new DataEvent(EventName.PlayerSuitSkillOpen));
            }
            Alert.resetToDefault();
            return;
        }

        public updateSkillState(arg1: string): void
        {
            if (arg1 == GModuleEvent.Mode_Self) 
            {
                this.onSuitSkillInfoCommandHandler(Cache.instance.role.suitSkillInfo);
            }
            return;
        }

        public updateSuitState(arg1: string): void
        {
            var loc1=null;
            var loc2=null;
            if (arg1 != GModuleEvent.Mode_Self) 
            {
                this._level = LookupPlayerData.miniPlayer.level;
                if (this._level >= 30) 
                {
                    if (this._suitLockBtn == null) 
                    {
                        this._suitLockBtn = ObjCreate.createGButton("", 0, 0, 23, 23, this, "SuitGrayBtn");
                    }
                    this._suitLockBtn.enabled = false;
                }
                else if (this._level < 30) 
                {
                    if (this._suitLockBtn && this._suitLockBtn.parent) 
                    {
                        removeChild(this._suitLockBtn);
                        this._suitLockBtn = null;
                    }
                }
                if (this._level >= 60) 
                {
                    if (this._suitSkillBtn == null) 
                    {
                        this._suitSkillBtn = ObjCreate.createGButton("", 0, 28, 23, 23, this, "SuitSkillBtn");
                    }
                    this._suitSkillBtn.enabled = false;
                }
                else if (this._level < 60) 
                {
                    if (this._suitSkillBtn && this._suitSkillBtn.parent) 
                    {
                        removeChild(this._suitSkillBtn);
                        this._suitSkillBtn = null;
                    }
                }
            }
            else 
            {
                loc1 = Cache.instance.role.suitCanLockCodes;
                loc2 = Cache.instance.role.suitLockedCodes;
                loc1 = this.filterCodes(loc1);
                loc2 = this.filterCodes(loc2);
                if (this._suitLockBtn != null) 
                {
                    EffectManager.glowFilterUnReg(this._suitLockBtn);
                    if ((loc1 == null || loc1.length <= 0) && (loc2 == null || loc2.length <= 0)) 
                    {
                        this._suitLockBtn.styleName = "SuitGrayBtn";
                    }
                    else if (!(loc1 == null) && loc1.length > 0 && (loc2 == null || loc2.length <= 0)) 
                    {
                        this._suitLockBtn.styleName = "SuitGrayBtn";
                        EffectManager.glowFilterReg(this._suitLockBtn, [this._glowYellow], 0.5, 10, 5, 0);
                    }
                    else if (!(loc2 == null) && loc2.length > 0) 
                    {
                        this._suitLockBtn.styleName = "SuitLockBtn";
                    }
                    this._suitLockBtn.toolTipData = this.getLockToolTipData(loc2, loc1);
                }
            }
            return;
        }

        /* internal  */filterCodes(arg1: Array<any>): Array<any>
        {
            if (arg1 == null) 
            {
                return null;
            }
            var loc1=[];
            var loc2=0;
            while (loc2 < arg1.length) 
            {
                if (arg1[loc2] > 0) 
                {
                    loc1.push(arg1[loc2]);
                }
                ++loc2;
            }
            return loc1;
        }

        /* internal  */getLockToolTipData(arg1: Array<any>, arg2: Array<any>): ToolTipInfo
        {
            var loc3=0;
            var loc4=0;
            var loc1="";
            var loc2=[];
            if (arg1 != null) 
            {
                loc4 = 0;
                while (loc4 < arg1.length) 
                {
                    loc3 = SecondCareerConfig.instance.getSecondCode(ECareerSecondTran._ECareerSecondSuit, arg1[loc4], Cache.instance.role.careerBasic, this._curCareer);
                    loc2.push(EquipmentUtil.getSuitTipByCode(loc3, true) + "\n");
                    ++loc4;
                }
            }
            if (arg2 != null) 
            {
                loc4 = 0;
                while (loc4 < arg2.length) 
                {
                    loc3 = SecondCareerConfig.instance.getSecondCode(ECareerSecondTran._ECareerSecondSuit, arg2[loc4], Cache.instance.role.careerBasic, this._curCareer);
                    loc2.push(EquipmentUtil.getSuitTipByCode(loc3, false) + "\n");
                    ++loc4;
                }
            }
            if (loc2.length <= 0) 
            {
                loc2.push("<font color=\'#b1efff\'>  " + Language.getString(30165) + "</font>\n\n");
            }
            loc2.push(Language.getString(30166));
            var loc5;
            return loc5 = new ToolTipInfo(NormalTooltip.ToolTipRenderType_Separate, loc2);
        }

        /* internal  */onSuitSkillInfoCommandHandler(arg1: SSuitSkillInfo): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=null;
            if (arg1) 
            {
                this._skillInfo = arg1;
                loc1 = "";
                if (arg1.skillId != 0) 
                {
                    if (arg1.skillId > 0) 
                    {
                        loc2 = arg1.skillId - arg1.level + 1;
                        loc2 = SecondCareerConfig.instance.getSecondCode(ECareerSecondTran._ECareerSecondSkill, loc2, Cache.instance.role.careerBasic, this._curCareer);
                        loc2 = (loc2 + arg1.level - 1);
                        loc3 = SkillConfig.instance.getInfoByName(loc2);
                        if (arg1.level > 0) 
                        {
                            loc1 = Language.getStringByParam(35989, loc3.skillName, arg1.level, loc3.skillDescription);
                        }
                        else 
                        {
                            loc1 = Language.getStringByParam(35990, loc3.skillName, 1, loc3.skillDescription);
                        }
                    }
                }
                else 
                {
                    loc1 = Language.getString(35988);
                }
                if (this._suitSkillBtn) 
                {
                    if (!Cache.instance.role.isSuitSkillRateAlert()) 
                    {
                        EffectManager.glowFilterUnReg(this._suitSkillBtn);
                    }
                    if (arg1.level > 0 && arg1.skillId > 0) 
                    {
                        this._suitSkillBtn.styleName = "SuitSkillBtn";
                    }
                    else if (arg1.skillId == 0) 
                    {
                        EffectManager.glowFilterUnReg(this._suitSkillBtn);
                        this._suitSkillBtn.styleName = "SuitGrayBtn";
                    }
                    this._suitSkillBtn.toolTipData = "<textFormat leading=\'5\'>" + HTMLUtil.addColor(loc1, "#ffffff") + "</textFormat>";
                }
            }
            return;
        }

        public updateSuitSkillRate(): void
        {
            if (!this._hasGlitter && Cache.instance.role.isSuitSkillRateAlert()) 
            {
                this._hasGlitter = true;
                EffectManager.glowFilterReg(this._suitSkillBtn, [this._glowYellow], 0.5, 10, 5, 0);
            }
            return;
        }

        /* internal */ /* var */_glowYellow: Object /* flash.filters.GlowFilter */;

        /* internal */ /* var */_level: int;

        /* internal */ /* var */_suitCanLock: Array<any>;

        /* internal */ /* var */_skillInfo: SSuitSkillInfo;

        /* internal */ /* var */_suitLockBtn: GButton;

        /* internal */ /* var */_suitSkillBtn: GButton;

        /* internal */ /* var */_mode: string="自己";

        /* internal */ /* var */_hasGlitter: Boolean;

        /* internal */ /* var */_curCareer: int;
    }
